#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int Judge_year(int year)
{
    if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    int year = 0;
    int month = 0;
    while (scanf("%d %d", &year, &month) != EOF)
    {
        if (month == 2)
        {
            int ret = Judge_year(year);
            if (ret == 1)
            {
                printf("%d\n", 29);
            }
            else
            {
                printf("%d\n", 28);
            }
        }
        else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
            printf("%d\n", 31);
        }
        else
        {
            printf("%d\n", 30);
        }
    }
    return 0;
}